<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../header.jsp">
<jsp:param value="部门管理" name="title"/>
</jsp:include>
<script type="text/javascript">
	function del(){
		$('#twodel').modal('show');
	}
	
	function add_dept(){
		var mo = $("#add_dept")
		mo.modal('show');
	}
	
	function affirm(){
			var checkeds = $(".item-check:checked");
				//获取所有选择的id
				var ids = [];
				checkeds.each(function() {
					ids.push(this.value);
				});
				location.replace("../business/dept/delete?id=" + ids.join("&id="));
	}
	
	$(function() {
		$('.selection.dropdown').dropdown();
		$("div.checkbox").checkbox();
		var checkAll = $("#checkAll");
		var itemCheck = $(".item-check");		
		checkAll.on("change", function() {
			//获取全选框选中状态
			itemCheck.prop("checked", this.checked)
		});

		itemCheck.on("change", function() {
			//判断判断选中的个数是否和所有存在个数一样
			var checkeds = $(".item-check:checked");
			//修改checkAll的checked属性
			checkAll.prop("checked", checkeds.length == itemCheck.length);
		});

		var delLogo = ${delLogo};
		
		if(delLogo == 1){
			var mo = $("#logo")
			mo.modal('show');
		}
		
		
		$("#update").click(function(){
			layer.open({
				  type: 2,
				  title: '修改密码:',
				  //offset: 'b',
				  shift: 2,
				  shadeClose: true,
				  maxmin: true,
				  shade: 0.8,
				  area: ['50%', '50%'],
				  content: "upadtepass.jsp"
		})
		
	})
	});
</script>
</head>
<body>

<div class = "gps">
<a class = "home" href="staff?method=forward">首页</a>
  <i class="right chevron icon divider"></i>
<a href="dept/manager">部门管理</a>
</div>
	<div class="teacher-content">
		<div class="searcher">
			<form>
				<div class="ui form">
					<div class="fields">
							<div class="field">
							<label>部门名称</label>
					        <input type="text" name="deptName" value="${param.deptName }"> 
					        </div>
							<div class="field">
							<label>部门经理</label> <input type="text" name="deptManager" value="${param.deptManager }">
							</div>					        <div class="field">
							<label>上属部门</label>
					        <input type="text" name="deptParent" value="${param.deptParent }">
					        </div>
					     	<div class="field">
							<label>&nbsp;</label>
							<button class="ui submit button">
							<i class="search icon"></i>
							检索</button>
						</div>
					
					</div>
				</div>
			</form>
		</div>
		<div>
			<div class="ui buttons">
				<a onclick="add_dept() " class="ui button"> <i class="icon user"></i>
					创建部门
				</a>
				
				<button class="ui red button" onclick = "del()">
					<i class="icon trash"></i> 删除部门
				</button>
			</div>
		</div>
		<table class="ui celled striped table">
			<thead>
				<tr>
					<th colspan="4">部门列表</th>
				</tr>
			</thead>
			<tbody>

				<tr>
					<td class="collapsing">
						<div class="ui checkbox">
							<input type="checkbox" id="checkAll" >
						</div>
					</td>
					<td >部门名称</td>
					<td >部门经理</td>
					<td >上属部门</td>
					<td>&nbsp;</td>
				</tr>
				 <c:forEach items="${deptList }" var="dept">
					   <tr>
					<td class="collapsing">
							<div class="ui checkbox">
								<input class="item-check" type="checkbox" value="${dept.deptId}">
							</div>
						</td>
						<td>${dept.deptName }</td>
						<td>${dept.deptManager }</td>
						<td>${dept.deptParent }</td>
						<td class="collapsing">
						<a  class="ui red button" onclick="return confirm('确认删除？')" href="../business/dept/delete?id=${dept.deptId}">
						<i class="icon trash"></i> 删除
						</a>
						<a  class="ui red button" href ="dept/update?did=${dept.deptId}">
						<i class="edit icon" ></i> 修改
						</a>
						</td>
					</tr>	
			</c:forEach>
			</tbody>
		</table>
	</div>
	<br>
<div class="ui right floated pagination menu" id = "page">
  	<c:if test="${pageSum > 1 }">  	
			<div class="page">
				<a <c:if test="${nowpage!=1}">href="dept/manager?nowpage=1${queryString}"</c:if>
					class="${nowpage == 1?'disable':''}">首页</a> <a
					<c:if test="${nowpage!=1}">href="dept/manager?nowpage=${nowpage-1}${queryString}"</c:if>
					class="${nowpage == 1?'disable':''}">上一页</a>
					<span>${nowpage}/${ pageSum} </span> <a
					<c:if test="${nowpage!=pageSum}">href="dept/manager?nowpage=${nowpage+1}${queryString}"</c:if>
					class="${nowpage == pageSum?'disable':''}">下一页</a> <a
					<c:if test="${nowpage!=pageSum}">href="dept/manager?nowpage=${pageSum }${queryString}"</c:if>
					class="${nowpage == pageSum?'disable':''}">最后一页</a> 
					
			</div>
		</c:if>
	</div>
	<div class="ui modal" id = "twodel">
			 <i class="close icon"></i>
			<div class="header">
			  删除部门
			 </div>
			<div class="image content" style="color : red"> 
			 <i class="warning circle icon"></i><p>你确定要删除所选部门</p>
			</div>
			 <div class="actions">
			  <div class="ui black deny button">
				      不
			  </div>
			<div class="ui positive right labeled icon button" onclick = "affirm()">
					     是的
				<i class="checkmark icon"></i>
				  </div>
			 </div>
	</div>
<div class="ui basic modal" id ="logo">
  <i class="close icon"></i>
  <div class="header">
  	删除结果:
  </div>
  <div class="content">
  <c:if test = "${delLogo eq 1}">
    <div class="image">
    <i class="warning sign icon"></i>
    </div>
    <div class="description">
      <p style="padding-left: 100px; color: red">${delError}删除失败！</p>
      <p style="padding-left: 100px">原因：部门中还有学员，不能进行此操作</p>
    </div>
    </c:if>
  </div>
  <div class="actions">
    <div class="two fluid ui inverted buttons">
  
    <div class="ui black deny button">
	确定
	<i class="checkmark icon"></i>
	</div>
    </div>
  </div>
</div>
<!--创建部门的弹出层  -->
<div class="ui modal" id = "add_dept">
  <div class="header">
  	 创建部门
  </div>
 <div class="teacher-content">
		<form  method="post" class="ui form create-form" action = "dept/add ">
		  <div class="field">
		    <label>部门名称</label>
		    <input type="text" name="addDeptName" required="required">
		  </div>
		   <div class="field">
		    <label>部门经理</label>
		    <input type="text" name="addDeptManager" required="required" >
		  </div>
		   <div class="field" required="required">
		    <label>上属部门</label>
		 <select  name="addDeptParent">
		<option selected="selected">选择部门
		<c:forEach items="${allDeptList}" var="dept">
			<option value = "${dept.deptName }">${dept.deptName }
		</c:forEach>
		</select>
		  </div>	
		  <div class="actions">
   <div class="ui black deny button">
				取消创建
			  </div>
  
    <button id="buts" >
      <div class="ui positive right labeled icon button" >
       	  确认创建
      <i class="checkmark icon"></i>
       </div>
    </button>   
  	</div> 
		</form>
	</div>  
</div>

</body>
</body>
</html>